package com.zzc.fwzpxt.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zzc.fwzpxt.entity.Comment;
import com.zzc.fwzpxt.service.ICommentService;
import com.zzc.common.controller.BaseController;
import com.zzc.common.result.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @User Administrator
 * @Date Create in 9:52/2017/9/28
 * @Descriptton { }
 **/
@Controller
@RequestMapping("/comment")
public class BlogCommentController extends BaseController{
    @Autowired
    private ICommentService iCommentService;

    /**
     * 获取留言列表
     * @return
     */
    @ResponseBody
    @RequestMapping("/getComment")
    public JsonResult getComment(){
        EntityWrapper<Comment> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("status",2);
        entityWrapper.orderBy("gmt_create", false);
        return renderSuccess(iCommentService.selectList(entityWrapper));
    }
    /**
     * 客户留言
     * @return
     */
    @ResponseBody
    @PostMapping("/addComment")
    public JsonResult addComment(Comment comment){
        comment.setStatus(1);
        return  iCommentService.insert(comment) ? renderSuccess("添加成功") : renderError("添加失败");
    }

}
